package com.example.aliyun.plus;
public class ThreadInterrupt implements Runnable {
    @Override
    public void run() {
        while (true) {
            if (Thread.currentThread().isInterrupted()) {
                System.out.println("我进入中断了，但我还在跑");
            } else {
                System.out.println("我没有进入中断");
            }
        }
    }

    public static void main(String[] args) {

        ThreadInterrupt runner3 = new ThreadInterrupt();
        Thread thread3 = new Thread(runner3);
        thread3.start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        thread3.interrupt(); // 线程中断
    }
}


